//
//  MyHeaderView.m
//  CarTown
//
//  Created by xionghao on 15/8/7.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "MyHeaderView.h"
#import "MyheaderBar.h"
#import "MyHeaderBarNotPower.h"
#import <UIImageView+WebCache.h>
#import "Address.h"
@interface MyHeaderView ()<MyheaderBarNotPowerViewClickDelegate,MyheaderBarViewClickDelegate>
@property (weak, nonatomic) IBOutlet UIView *bar;
@property (weak, nonatomic) IBOutlet UIView *notbar;
@property (weak, nonatomic) IBOutlet UILabel *fav_count1;
@property (weak, nonatomic) IBOutlet UILabel *atten_count1;
@property (weak, nonatomic) IBOutlet UILabel *fav_count2;
@property (weak, nonatomic) IBOutlet UIButton *updatebtn;


@end

@implementation MyHeaderView
+(instancetype)header{
    MyHeaderView *header=[[[NSBundle mainBundle]loadNibNamed:@"MyHeaderView" owner:nil options:nil]lastObject];
    
    return header;
}
-(void)HeadViewBarNotPowerclickWithIndex:(NSInteger)index{
    [self clickWithTag:index];
}
-(void)HeadViewBarclickWithIndex:(NSInteger)index{
    [self clickWithTag:index];
}


-(void)setPuser:(Puser *)puser{
    _puser=puser;
   NSInteger power= [_puser.power integerValue];
    if (power!=1&&power!=5&&power!=8) {
        self.notbar.hidden=NO;
        self.bar.hidden=YES;
    }else{
        self.notbar.hidden=YES;
        self.bar.hidden=NO;
    }
    NSString *iconurl;
    
    if (power<5) {
       self.name.text=_puser.user_truename;
        Address *pro=[Address getAdressbyID:_puser.user_province];
        Address *city=[Address getAdressbyID:_puser.user_city];
        
        self.addresslable.text=[NSString stringWithFormat:@"%@%@市",pro.area_name,city.area_name];
         iconurl=[NSString getImageURLstr: _puser.user_ico];
        
    }else{
        Address *pro=[Address getAdressbyID:_puser.shop_province];
        Address *city=[Address getAdressbyID:_puser.shop_city];
        self.name.text=_puser.com_username;
        self.addresslable.text=[NSString stringWithFormat:@"%@%@市",pro.area_name,city.area_name];
        iconurl=[NSString getImageURLstr: _puser.shop_logo];
    }
    
    
    
        [self.icon sd_setImageWithURL:[NSURL URLWithString:iconurl] placeholderImage:[UIImage imageNamed:@"usericon_placehoder"]];
    
    self.fav_count1.text=_puser.fav_count;
    self.fav_count2.text=_puser.fav_count;
    self.atten_count1.text=_puser.atten_count;
}

-(void)awakeFromNib{
    self.width=XHScreenwidth;
    self.icon.layer.cornerRadius=self.icon.width/2;
    [self.icon clipsToBounds];
    self.icon.layer.borderWidth=1;
    self.icon.layer.borderColor=[UIColorWithRGB(238, 238, 238) CGColor];
    self.updatebtn.layer.cornerRadius=8;
    self.updatebtn.clipsToBounds=YES;
    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click:)];
    self.guanzhuview.userInteractionEnabled=YES;
    [self.guanzhuview addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click:)];
    self.favview1.userInteractionEnabled=YES;
    [self.favview1 addGestureRecognizer:tap2];
     UITapGestureRecognizer *tap3=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click:)];
    self.favview2.userInteractionEnabled=YES;
    [self.favview2 addGestureRecognizer:tap3];
    UITapGestureRecognizer *tap4=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click:)];
    self.shengji.userInteractionEnabled=YES;
    [self.shengji addGestureRecognizer:tap4];
    UITapGestureRecognizer *tap5=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click:)];
    self.shengji2.userInteractionEnabled=YES;
    [self.shengji2 addGestureRecognizer:tap5];
}

-(void)click:(UIGestureRecognizer *)tap{
   UIView *view= tap.view;
    if ([_delegate respondsToSelector:@selector(HeadViewclickWithIndex:)]) {
        [_delegate HeadViewclickWithIndex:view.tag];
    }
   
   
}

-(void)clickWithTag:(NSInteger)tag{
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
